//
//  TKL_videodetailVC.m
//  TKL_EnPro
//
//  Created by 雅恩三河科技 on 2018/12/13.
//  Copyright © 2018年 MrZhang. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "TKL_videodetailVC.h"
#import <ZFPlayer/ZFPlayer.h>
#import <ZFPlayer/ZFPlayerControlView.h>
#import <ZFPlayer/ZFAVPlayerManager.h>
#import "UIImageView+ZFCache.h"
#import "ZFUtilities.h"
#import "Head.h"
#import "TKL_VideoCommentCell.h"
@interface TKL_videodetailVC ()<UITextFieldDelegate>
@property (nonatomic, strong) ZFPlayerController *player;
@property (nonatomic, strong) UIImageView *containerView;
@property (nonatomic, strong) ZFPlayerControlView *controlView;
@property (nonatomic, strong) UIButton *commentBtn;
@property(nonatomic,strong)NSMutableArray* dataSource;
@property(nonatomic,strong)NSMutableDictionary* detailData;
@property(nonatomic,strong)UIButton* MesBtn;


@property (nonatomic,strong) UIView *btomView;
@property (nonatomic,strong) UIButton *priseBtn;
@property (nonatomic,strong) UITextField *inputTF;
@end

@implementation TKL_videodetailVC
#pragma mark - getter and setter
-(UITextField *)inputTF
{
    if (!_inputTF) {
        _inputTF = [[UITextField alloc]init];
        _inputTF.x=WFCGFloatX(15);
        _inputTF.y=WFCGFloatY(7);
        _inputTF.width=WFCGFloatX(310);
        _inputTF.height=WFCGFloatY(32);
        _inputTF.font = SYSTEMFONT(15);
        _inputTF.textColor = Main_Color_Black;
        _inputTF.delegate = self;
        _inputTF.placeholder=@"添加评论";
        _inputTF.returnKeyType=UIReturnKeySend;
        [WFFunctions WFUIaddbordertoView:_inputTF radius:0 width:1 color:HEXCOLOR(@"#EEEEEE")];
        
        UIView* backView=[UIView new];
        backView.x=WFCGFloatX(0);
        backView.y=WFCGFloatY(0);
        backView.height=WFCGFloatY(32);
        backView.width=WFCGFloatX(32);
        backView.backgroundColor=HEXCOLOR(@"#F9F9F9");
        
        
        UIImageView* markIV=[UIImageView new];
        markIV.image=[UIImage imageNamed:@"new_edite"];
        markIV.width=WFCGFloatX(12);
        markIV.height=WFCGFloatX(12);
        markIV.x=WFCGFloatX(10);
        markIV.y=(backView.height-markIV.height)/2;
        [backView addSubview:markIV];
        _inputTF.leftView=backView;
        _inputTF.leftViewMode=UITextFieldViewModeAlways;
    }
    return _inputTF;
}
-(UIButton *)priseBtn
{
    if (!_priseBtn) {
        @WeakSelf;
        _priseBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        UIImage* image1=[UIImage imageNamed:@"new_praise_sel"];
        UIImage* image=[UIImage imageNamed:@"new_praise"];
        [_priseBtn setBackgroundImage:image forState:UIControlStateNormal];
        [_priseBtn setBackgroundImage:image1 forState:UIControlStateSelected];
        _priseBtn.width=WFCGFloatX(26);
        _priseBtn.height=WFCGFloatX(26);
        _priseBtn.x=WFCGFloatX(334);
        _priseBtn.y=(WFCGFloatY(45)-_priseBtn.height)/2;
        [_priseBtn setEnlargeEdge:15];
        [_priseBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
            
                        if ([TKL_LoginViewModel shareInterface].isLogin)
                        {
                            selfp.priseBtn.selected=!selfp.priseBtn.selected;
                        }else
                        {
                            [[GCPresenter shareInterface] loadLogin];
                        }
        }];
    }
    return _priseBtn;
}
-(UIView *)btomView
{
    if (!_btomView)
    {
        _btomView=[UIView new];
        _btomView.x=WFCGFloatX(0);
        _btomView.y= SCREEN_HEIGHT-[self bottomShelterHeight]-WFCGFloatY(45);
        _btomView.height=WFCGFloatY(45);
        _btomView.width=WFCGFloatX(375);
        _btomView.backgroundColor=HEXCOLOR(@"#F9F9F9");
        
        [WFFunctions WFUIaddBorderToView:_btomView top:1 left:0 bottom:0 right:0 borderColor:HEXCOLOR(@"#EEEEEE") borderWidth:1];
    }
    return _btomView;
}

-(UIButton *)MesBtn
{
    @WeakSelf;
    if (!_MesBtn)
    {
        _MesBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        UIImage* btnImage=[UIImage imageNamed:@"video_col"];
        UIImage* selImage=[UIImage imageNamed:@"video_col_sek"];
        [_MesBtn setBackgroundImage:selImage forState:UIControlStateSelected];
        [_MesBtn setBackgroundImage:btnImage forState:UIControlStateNormal];
        _MesBtn.width=btnImage.size.width;
        _MesBtn.height=btnImage.size.width;
        _MesBtn.x=WFCGFloatX(327);
        _MesBtn.y=(WFCGFloatY(30)-_MesBtn.height)/2+WFCGFloatY(5);
        [_MesBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
            
            if (![TKL_LoginViewModel shareInterface].isLogin) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[GCPresenter shareInterface] loadLogin];
                });
            }else
            {
                if ([[selfp.detailData objectForKey:@"collect"] integerValue]==1)
                {
                    selfp.MesBtn.selected=NO;
                    [selfp.detailData setObject:@"0" forKey:@"collect"];
                    [selfp requestAddCollect:@"0"];
                }else
                {
                    selfp.MesBtn.selected=YES;
                    [selfp.detailData setObject:@"1" forKey:@"collect"];
                    [selfp requestAddCollect:@"1"];
                }
            }
        }];
        
    }
    return _MesBtn;
}
-(NSMutableDictionary *)detailData
{
    if (!_detailData) {
        _detailData=[NSMutableDictionary new];
    }
    return _detailData;
}
-(NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource=[NSMutableArray new];
    }
    return _dataSource;
}
- (ZFPlayerControlView *)controlView {
    if (!_controlView) {
        _controlView = [ZFPlayerControlView new];
        _controlView.fastViewAnimated = YES;
    }
    return _controlView;
}

- (UIImageView *)containerView {
    if (!_containerView) {
        _containerView = [UIImageView new];
        
        [_containerView setImageWithURLString:[_passData objectForKey:@"cover"] placeholder:[ZFUtilities imageWithColor:[UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1] size:CGSizeMake(1, 1)]];
    }
    return _containerView;
}
-(UIButton *)commentBtn
{
    if (!_commentBtn)
    {
        @WeakSelf;
        _commentBtn = [[UIButton alloc]init];
        
        _commentBtn.width=SCREEN_WIDTH;
        _commentBtn.height=WFCGFloatY(40);
        _commentBtn.x=0;
        _commentBtn.y=SCREEN_HEIGHT-WFCGFloatY(40);
        [_commentBtn setTitle:@"评价" forState:UIControlStateNormal];
        [_commentBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _commentBtn.backgroundColor=Main_Color;
        _commentBtn.titleLabel.font = SYSTEMFONT(15);
        [_commentBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
            
            if ([TKL_LoginViewModel shareInterface].isLogin)
            {
                TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"评价内容" message:@""];
                [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) {
                    NSLog(@"%@",action.title);
                }]];
                
                // 弱引用alertView 否则 会循环引用
                __typeof (alertView) __weak weakAlertView = alertView;
                [alertView addAction:[TYAlertAction actionWithTitle:@"确定" style:TYAlertActionStyleDestructive handler:^(TYAlertAction *action) {
                    for (UITextField *textField in weakAlertView.textFieldArray) {
                        NSLog(@"%@",textField.text);
                        if ([WFFunctions WFStrCheckEmpty:textField.text]) {
                            [FTIndicator showErrorWithMessage:@"请填写评价内容"];
                        }else
                        {
                            [selfp requestAddComment:textField.text];
                        }
                    }
                }]];
                
                [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                    [textField becomeFirstResponder];
                    
                }];
                // first way to show
                TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert];
                alertController.backgoundTapDismissEnable=YES;
                alertController.alertViewOriginY=[self topShelterHeight]+60;
                [selfp presentViewController:alertController animated:YES completion:nil];
                
            }else
            {
                [[GCPresenter shareInterface] loadLogin];;
            }
            
        }];
    }
    return _commentBtn;
}
#pragma mark - event
#pragma mark - method
-(void)initilization
{
    
    @WeakSelf;

   // self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:selfp.MesBtn];;

    self.isGroup=YES;
    if (@available(iOS 11.0, *)) {
        self.baseTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.navigationController.navigationBar.shadowImage = [[UIImage new]rt_darkenWithLevel:0.3f];
    
    
    self.baseTable.contentInset = UIEdgeInsetsMake([self topShelterHeight]+SCREEN_WIDTH*9/16, 0, [self bottomShelterHeight]+WFCGFloatY(45), 0);
    
    [self.view addSubview:self.baseTable];
    [self.view addSubview:self.btomView];
    [self.btomView addSubview:self.inputTF];
    [self.btomView addSubview:self.priseBtn];

    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    [self.baseTable setSeparatorColor: Main_Color_BG];
    [self.baseTable setBackgroundColor:[UIColor whiteColor]];
    [self.baseTable setTintColor:Main_Color_BG];
    
    
    self.baseTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [selfp reloadData];
        [selfp.baseTable.mj_header endRefreshing];
    }];
    
    [self viewModelBand];
    [self reloadData];
    
    
    
    [self.view addSubview:self.containerView];
    self.view.backgroundColor=[UIColor whiteColor];
    self.navigationItem.title = [_passData objectForKey:@"title"];
    
    ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
    /// 播放器相关
    self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.containerView];
    self.player.controlView = self.controlView;
    /// 设置退到后台继续播放
    self.player.pauseWhenAppResignActive = NO;
    @weakify(self)
    self.player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
        @strongify(self)
        [self setNeedsStatusBarAppearanceUpdate];
    };
    
    self.player.playerDidToEnd = ^(id  _Nonnull asset) {
        @strongify(self)
        [self.player.currentPlayerManager replay];
    };
    
    self.player.playerReadyToPlay = ^(id<ZFPlayerMediaPlayback>  _Nonnull asset, NSURL * _Nonnull assetURL) {
        NSLog(@"======开始播放了");
    };
    
    self.player.assetURLs = @[[NSURL URLWithString:[[_passData objectForKey:@"content"] objectForKey:@"url"]]];
    [self playClick:nil];
   // [self.view addSubview:self.commentBtn];
    
}
-(void)viewModelBand
{
    @WeakSelf;
    //
}
-(void)reloadData
{
    [self rquestDetail];
    [self requestCommnet:[NSMutableDictionary new]];
  //  [self.viewModel requestBlogList:[_passDic objectForKey:@"objectId"]];
}
-(void)reloadView
{
    
}
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    CGFloat x = 0;
    CGFloat y = [self topShelterHeight];
    CGFloat w = CGRectGetWidth(self.view.frame);
    CGFloat h = w*9/16;
    self.containerView.frame = CGRectMake(x, y, w, h);
}
- (void)playClick:(UIButton *)sender {
    [self.player playTheIndex:0];
   // [self.controlView showTitle:@"" coverURLString:@"" fullScreenMode:ZFFullScreenModeLandscape];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
    if (self.player.isFullScreen) {
        return UIStatusBarStyleLightContent;
    }
    return UIStatusBarStyleDefault;
}
- (BOOL)prefersStatusBarHidden {
    /// 如果只是支持iOS9+ 那直接return NO即可，这里为了适配iOS8
    return self.player.isStatusBarHidden;
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationSlide;
}

- (BOOL)shouldAutorotate {
    return self.player.shouldAutorotate;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    if (self.player.isFullScreen) {
        return UIInterfaceOrientationMaskLandscape;
    }
    return UIInterfaceOrientationMaskPortrait;
}
#pragma mark - life
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.player.viewControllerDisappear = NO;
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.player.viewControllerDisappear = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    [self initilization];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - delegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==1) {
        return self.dataSource.count;
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section==0)
    {
        static NSString *CellID = @"CellID";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        [cell.contentView removeAllSubviews];
        
        UILabel* titleLab=[UILabel new];
        titleLab.x=WFCGFloatX(10);
        titleLab.y=WFCGFloatY(5);
        titleLab.width=WFCGFloatX(355);
        titleLab.textAlignment=NSTextAlignmentLeft;
        
        titleLab.font=SYSTEMFONT(15);
        titleLab.textColor=HEXCOLOR(@"#333333");
        titleLab.text=[[_passData objectForKey:@"content"] objectForKey:@"text"];
        titleLab.numberOfLines=0;
        [cell.contentView addSubview:titleLab];
        CGSize temSize=[WFFunctions WFStrGetSize:titleLab.text width:WFCGFloatX(355) font:SYSTEMFONT(15)];
        titleLab.height=temSize.height;
        
    
        return cell;
    }
    static NSString *CellID = @"CellID";
    TKL_VideoCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[TKL_VideoCommentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    [cell setModel:self.dataSource[indexPath.row]];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0)
    {
        CGSize temSize=[WFFunctions WFStrGetSize:[[_passData objectForKey:@"content"] objectForKey:@"text"] width:WFCGFloatX(355) font:SYSTEMFONT(15)];
        return temSize.height+WFCGFloatY(20);
    }
    NSDictionary* dic=_dataSource[indexPath.row];
    CGSize temSize=[WFFunctions WFStrGetSize:[dic objectForKey:@"content"] width:SCREEN_WIDTH-WFCGFloatX(55) font:SYSTEMFONT(12)];
    return WFCGFloatY(50)+temSize.height+WFCGFloatY(5);
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=[UIColor whiteColor];
    if (section==1)
    {
        UILabel* lookLab=[UILabel new];
        lookLab.x=WFCGFloatX(10);
        lookLab.y=WFCGFloatY(0);
        lookLab.width=WFCGFloatX(100);
        lookLab.height=WFCGFloatY(40);
        lookLab.font=SYSTEMFONT(15);
        lookLab.textColor=HEXCOLOR(@"#333333");
        lookLab.text=@"评价";
        [view addSubview:lookLab];
    }
    
    return view;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=Main_Color_BG;
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section==0) {
        return WFCGFloatY(5);
    }
    return .0001f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==1) {
        return WFCGFloatY(40);
    }
    return .00001f;
}

-(void)rquestDetail
{
    @WeakSelf;
    //
    NSMutableDictionary* para=[NSMutableDictionary new];
    [para setObject:[_passData objectForKey:@"uuid"] forKey:@"posterUuid"];
    if ([TKL_LoginViewModel shareInterface].isLogin)
    {
       // [para setObject:[TKL_LoginViewModel shareInterface].infoModel.uuid forKey:@"userUuid"];
    }
    
    [[InterfaceManager shareInterface] requestAllInterface:@"http://101.201.171.131:8080/rest/api/home/poster/detail" para:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        selfp.detailData=[[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:@"data"]];;
        if ([[selfp.detailData objectForKey:@"collect"] integerValue]==0)
        {
            selfp.MesBtn.selected=NO;
        }else
        {
            selfp.MesBtn.selected=YES;
        }
    }];
}
-(void)requestCommnet:(NSMutableDictionary*)para
{
    @WeakSelf;
    //base=0&order=1&page=1&posterUuid=5b5a48a9-59f0-40bd-b67b-5e4f81cee346
    
    [para setObject:@"0" forKey:@"base"];
    [para setObject:[_passData objectForKey:@"uuid"] forKey:@"posterUuid"];
    [para setObject:@"1" forKey:@"order"];
    [para setObject:@"1" forKey:@"page"];
    
    [[InterfaceManager shareInterface] requestAllInterface:@"http://101.201.171.131:8080/rest/api/poster/comment/list" para:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        [selfp.dataSource removeAllObjects];
        NSArray* arr=[info objectForKey:@"dataList"];
        for (NSDictionary* dic in arr) {
            [selfp.dataSource addObject:dic];
        }
        [selfp.baseTable reloadData];
    }];
    
    
}
-(void)requestAddComment:(NSString*)content
{
    //http://101.201.171.131:8080/rest/api/community/comment/add
    NSMutableDictionary* para=[NSMutableDictionary new];
    [para setObject:content forKey:@"content"];
    [para setObject:@"0" forKey:@"replyTo"];
    [para setObject:[TKL_LoginViewModel shareInterface].infoModel.uuid forKey:@"userUuid"];
    [para setObject:[_passData objectForKey:@"uuid"] forKey:@"posterUuid"];
    [[InterfaceManager shareInterface] requestAllInterface:@"http://101.201.171.131:8080/rest/api/poster/comment/add" para:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        [self requestCommnet:[NSMutableDictionary new]];
    }];
}
////http://101.201.171.131:8080/rest/api/home/poster/collect/ 收藏视频  collect=1&posterUuid=5b5a48a9-59f0-40bd-b67b-5e4f81cee346&userUuid=63e5eeec-588a-4c66-9356-ab7b4313a020
-(void)requestAddCollect:(NSString*)content
{
    //http://101.201.171.131:8080/rest/api/community/comment/add
    NSMutableDictionary* para=[NSMutableDictionary new];
    [para setObject:content forKey:@"collect"];
    [para setObject:[TKL_LoginViewModel shareInterface].infoModel.uuid forKey:@"userUuid"];
    [para setObject:[_passData objectForKey:@"uuid"] forKey:@"posterUuid"];
    [[InterfaceManager shareInterface] requestAllInterface:@"http://101.201.171.131:8080/rest/api/home/poster/collect" para:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        
    }];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"哈哈哈");
    if ([TKL_LoginViewModel shareInterface].isLogin)
    {
        if ([WFFunctions WFStrCheckEmpty:textField.text]) {
            [FTIndicator showErrorWithMessage:@"请填写评价内容"];
        }else
        {
            [self requestAddComment:textField.text];
            self.inputTF.text=@"";
        }
        
    }else
    {
        [[GCPresenter shareInterface] loadLogin];
    }
    [self.inputTF resignFirstResponder];
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{

}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
